package com.david.warehouse.controller;

import com.david.warehouse.pojo.entity.Product;
import com.david.warehouse.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static com.david.common.utils.ResultUtils.success;

@RestController
@RequestMapping("/whm/product")
@Slf4j
@Api(tags = "仓库管理-物料管理")
public class ProductController {
    @Autowired
    private ProductService productService;

    @PostMapping("/add")
    @ApiOperation(value = "添加/修改物料")
    public ResponseEntity<Object> addProduct(@RequestBody Product product)
    {
        log.info("addProduct:{}",product);
        String result = productService.addProduct(product);
        return success(true, result);
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取物料列表")
    public ResponseEntity<Object> getProductList(@RequestParam("categoryId") String categoryId,
                                                 @RequestParam("typeId") String typeId)
    {
        log.info("getProductList>>>>>categoryId:{},typeId:{}",categoryId,typeId);
        return success(true, productService.getProductList(categoryId,typeId));
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除物料")
    public ResponseEntity<Object> deleteProduct(@PathVariable Integer id)
    {
        log.info("deleteProduct:{}",id);
        productService.deleteProductById(id);
        return success(true, "删除成功");
    }
}
